package org.hbnu.xiaomi.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hbnu.xiaomi.entity.Goods;

import java.util.List;

//商品实体查询接口
@Mapper
public interface GoodsMapper {

    // 按编号获取商品
    @Select("SELECT id, name, pic, price, stock, types_id, detail FROM goods WHERE id = #{id}")
    Goods getById(int id);

    // 按照类型编号获取商品
    @Select("SELECT id, name, pic, price, stock, types_id, detail FROM goods WHERE types_id = #{types_id}")
    List<Goods> getByTypesId(int types_id);

    // 获取所有商品
    @Select("SELECT id, name, pic, price, stock, types_id, detail FROM goods")
    List<Goods> getAll();

    // 更新商品
    @Update("UPDATE goods SET name = #{name}, pic = #{pic}, price = #{price}, stock = #{stock}, types_id = #{types_id}, detail = #{detail} WHERE id = #{id}")
    void update(Goods goods);

    //删除商品
    @Delete("DELETE FROM goods WHERE id = #{id}")
    void deleteById(int id);
}
